本文描述了如何通过单机三个msyql实例,创建一个Single-Primary Innodb cluster,并通过mysql Router对connections实现路由,实现高可用性。
This section explains how to set up a single-primary InnoDB cluster and configure MySQL Router to achieve high availability.
This tutorial shows how to use MySQL Shell to create an InnoDB cluster consisting of a MySQL Server instance which provides the seed instance of the InnoDB cluster and holds the initial data set. Two more MySQL server instances are created and added to the InnoDB cluster. Then MySQL Router is deployed and used to route connections to the InnoDB cluster, and high availability is tested.
1. 安装3个mysql实例
注意:修改root密码时候设置SQL_LOG_BIN=0;
|
|
2. Yum 安装MySQL Shell
|
|
3. Configuring the Instance
检查并配置3个数据库实例
|
|
详细过程如下所示
|
|
重启3个数据库实例
|
|
重新检查3个实例,确保结果ok
|
|
4. Creating the InnoDB Cluster
Connect MySQL Shell to the seed instance, in this case the one at port 3301:
|
|
Use the createCluster()
method to create the InnoDB cluster with the currently connected instance as the seed:
|
|
5. Adding Instances to an InnoDB Cluster
配置/etc/hosts
|
|
Obtaining the cluster
Instance Variable
|
|
Add the second instance to the InnoDB cluster:
|
|
Add the third instance:
|
|
查看cluster 状态
|
|
6. 持久化配置文件
已经在cluster中的实例,第二次运行dba.configureLocalInstance(‘root@localhost:3301’),会将配置cluster的配置持久化到my.cnf
必须使用localhost
连接后在每个实例单独执行
|
|
7. 安装配置 MySQL Router
Yum安装
|
|
bootstrap 生成配置文件
|
|
配置文件/etc/mysqlrouter/mysqlrouter.conf
内容
|
|
启动mysqlrouter(记得修改下权限 默认权限不对)
|
|
测试连接
|
|
8. Testing Failover
killing the PRIMARY
instance 3301
|
|
测试连接(第一次失败,第二次成功)
|
|
查看cluster状态, 可以发现3302实例已经变成Primary
|
|
bring the instance that you killed back online.
|
|
重新查看cluster状态
|
|